package com.example.web;

import com.example.model.UserDomain;
import com.example.service.UserService;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.stereotype.Controller;
//import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.*;

import java.util.List;

//@Controller
@RestController
@RequestMapping(value = "/user")
public class UserController {
    @Autowired
    private UserService userService;


    @ResponseBody
//    @PostMapping("/add")
    @RequestMapping("/add")
    public int addUser(UserDomain user){
        return userService.addUser(user);
}

    @ResponseBody
    @RequestMapping("/all")
    public PageInfo<UserDomain> findAllUser(@RequestParam(name = "pageNum", required = false, defaultValue = "1") int pageNum,
                                            @RequestParam(name = "pageSize", required = false, defaultValue = "10") int pageSize){
        return userService.findAllUser(pageNum,pageSize);
    }

    @RequestMapping("/getUserByName/{name}")
    public List<UserDomain> getUserByName(@PathVariable String name) {
        return userService.getUserByName(name);
    }


}
